PasswordWindow = function(){
	var this_window = this;
	
	var validatePassword = function(){
		var pwd = form.newP.getValue();
		var rep = form.repP.getValue();
		if(pwd !== rep){
			notice_result_info("新密码与确认密码输入不一致");
			return false;
		}
		return true;
	};
	
	var form = new Ext.FormPanel({
		frame : true,
		padding : 10,
		labelWidth : 80,
		defaults : {
			xtype : "textfield",
			inputType : "password",
			allowBlank : false,
			anchor : "90%",
			minLength : 5,
			maxLength : 12
		},
		items : [{
			ref : "oldP",
			fieldLabel : "原密码"
		},{
			ref : "newP",
			fieldLabel : "新密码"
		},{
			ref : "repP",
			fieldLabel : "确认密码"
		}]
	});
	
	var save = function(){
		if(!form.form.isValid()){
			return false;
		}
		if(!validatePassword()){
			return false;
		}
		var oldP = form.oldP.getValue();
		var newP = form.newP.getValue();
		var username = getCookie('username');
		var purview = getCookie('purview');
		if(purview != "0"){
			var params = {
				"manager.name":username,
				"manager.password":MD5(oldP),
				"newPassword":MD5(newP)
			}
			Ajax({
				url : "manager/changePassword",
				params : params,
				maskTarget : this_window,
				window : this_window
			});
		}
		
	};
	
	PasswordWindow.superclass.constructor.call(this, {
		title : "修改密码",
		modal : true,
		width : 350,
		height : 200,
		layout : "fit",
		border : false,
		closeAction : "hide",
		items : [form],
		buttons : [{
			text : "保存",
			handler : save
		},{
			text : "取消",
			handler : function(){
				this_window.hide();
			}
		}],
		listeners : {
			hide : function(){
				form.form.reset();
			}
		}
	});
};
Ext.extend(PasswordWindow, Ext.Window);
var passwordWindow = new PasswordWindow();